package com.xingda.packing.dmds.http;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xingda.packing.dmds.config.appset.AppSetUrl;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
 * 装箱要求
 *
 * @author LEGION
 */
public class PackingRequireHttp {

    /**
     * @param pkPackorder 装箱计划
     * @param state       状态(0:未装箱)
     */
    public static JSONObject packinglist(String pkPackorder, String state) {
        List<NameValuePair> list = new LinkedList<>();
        BasicNameValuePair param1 = new BasicNameValuePair("pkPackorder", pkPackorder);
        BasicNameValuePair param2 = new BasicNameValuePair("state", state);
        list.add(param1);
        list.add(param2);
        try {
            JSONObject entityJson = BaseHttp.get(AppSetUrl.packing_list_url, list);
            if (entityJson.getIntValue("code") == 0 && "success".equals(entityJson.getString("msg"))) {
                return entityJson;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    /**
     * 获取中筒信息
     *
     * @param pkCalbody        分厂主键
     * @param pkInvbasdoc      物料主键
     * @param pkInspectionmode 检验方案（装箱传：0001LLIM000000000004）
     * @param vfree1           客户
     * @param vfree2           工字轮类型
     */
    public static JSONArray inspectionplanb(String pkCalbody, String pkInvbasdoc, String pkInspectionmode, String vfree1, String vfree2) {

        List<NameValuePair> list = new LinkedList<>();
        BasicNameValuePair param1 = new BasicNameValuePair("pkCalbody", pkCalbody);
        BasicNameValuePair param2 = new BasicNameValuePair("pkInvbasdoc", pkInvbasdoc);
        BasicNameValuePair param3 = new BasicNameValuePair("pkInspectionmode", pkInspectionmode);
        BasicNameValuePair param4 = new BasicNameValuePair("vfree1", vfree1);
        BasicNameValuePair param5 = new BasicNameValuePair("vfree2", vfree2);
        list.add(param1);
        list.add(param2);
        list.add(param3);
        list.add(param4);
        list.add(param5);
        JSONArray returnJson = null;
        try {
            JSONObject entityJson = BaseHttp.get(AppSetUrl.packing_check_url, list);
            if (entityJson.getIntValue("code") == 0 && "success".equals(entityJson.getString("msg"))) {
                JSONArray result = entityJson.getJSONArray("result");
                if (Objects.nonNull(result) && !result.isEmpty()) {
                    returnJson = result;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnJson;

    }

    /**
     * 查询单个中筒详情
     *
     * @param pkPacking     中筒主键
     * @param bPackInvWeigh 是否查询包装物称重
     * @param bPackList     是否查询装箱工字轮
     * @param bPackbInvplan 是否查询包装物计划
     * @param bBom          是否查询允许装箱物料
     */
    public static JSONObject searchPackingBoxInspection(String pkPacking, boolean bPackInvWeigh, boolean bPackList, boolean bPackbInvplan, boolean bBom) {

        List<NameValuePair> list = new LinkedList<>();
        BasicNameValuePair param1 = new BasicNameValuePair("pkPacking", pkPacking);
        BasicNameValuePair param2 = new BasicNameValuePair("bPackInvWeigh", Boolean.toString(bPackInvWeigh));
        BasicNameValuePair param3 = new BasicNameValuePair("bPackList", Boolean.toString(bPackList));
        BasicNameValuePair param4 = new BasicNameValuePair("bPackbInvplan", Boolean.toString(bPackbInvplan));
        BasicNameValuePair param5 = new BasicNameValuePair("bBom", Boolean.toString(bBom));
        list.add(param1);
        list.add(param2);
        list.add(param3);
        list.add(param4);
        list.add(param5);
        JSONObject returnJson = null;
        try {
            JSONObject entityJson = BaseHttp.get(AppSetUrl.packing_tube_url, list);

            if (Objects.nonNull(entityJson) && !entityJson.isEmpty() && entityJson.getIntValue("code") == 0 && "success".equals(entityJson.getString("msg"))) {
                JSONObject result = entityJson.getJSONObject("result");
                if (Objects.nonNull(result) && !result.isEmpty()) {
                    returnJson = result;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnJson;
    }
}
